﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
using System.Collections.Generic;
namespace CADTool.Jig
{
    public class BZJig : DrawJig
    {
        private DBText upText;
        private DBText downText;
        private Line leaderLine;
        private Line textLine;
        public BZJig(DBText upText, DBText downText, Line leaderLine, Line textLine)
        {
            this.upText = upText;
            this.downText = downText;
            this.leaderLine = leaderLine;
            this.textLine = textLine;
        }
        public List<Entity> GetEntity()
        {
            return new List<Entity>() { upText,downText,leaderLine,textLine};
        }
        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            PromptPointResult ppr = prompts.AcquirePoint("\n请选择第二点");
            if (ppr.Status == PromptStatus.Cancel)
            {
                return SamplerStatus.Cancel;
            }
            if (ppr.Status == PromptStatus.OK)
            {
                Point3d temp = ppr.Value;
                if (temp != leaderLine.StartPoint)
                {
                    leaderLine.EndPoint= ppr.Value;
                    Matrix3d mt = Matrix3d.Displacement(ppr.Value-(ppr.Value.X>=leaderLine.StartPoint.X? textLine.StartPoint:textLine.EndPoint));
                    textLine.TransformBy(mt);
                    upText.TransformBy(mt);
                    downText.TransformBy(mt);
                    return SamplerStatus.OK;
                }
            }
            return SamplerStatus.NoChange;
        }
        protected override bool WorldDraw(WorldDraw draw)
        {
            draw.Geometry.Draw(upText);
            draw.Geometry.Draw(downText);
            draw.Geometry.Draw(leaderLine);
            draw.Geometry.Draw(textLine);
            return true;
        }
    }
}
